package com.ruoyi.web.controller.hotel;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.LyhmsRoom;
import com.ruoyi.hotel.service.ILyhmsRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Controller
 * @author ruoyi
 * @date 2022-02-28
 */
@RestController
@RequestMapping("/system/room")
public class LyhmsRoomController extends BaseController {
    @Autowired
    private ILyhmsRoomService lyhmsRoomService;

    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LyhmsRoom lyhmsRoom) {
        startPage();
        List<LyhmsRoom> list = lyhmsRoomService.selectLyhmsRoomList(lyhmsRoom);
        return getDataTable(list);
    }


    @GetMapping("listRoom")
    public AjaxResult listRoom(LyhmsRoom lyhmsRoom) {

        List<LyhmsRoom> list = lyhmsRoomService.selectLyhmsRoomList(lyhmsRoom);
        return AjaxResult.success().put("list", list);
    }

    /**
     * 导出列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, LyhmsRoom lyhmsRoom) {
        List<LyhmsRoom> list = lyhmsRoomService.selectLyhmsRoomList(lyhmsRoom);
        ExcelUtil<LyhmsRoom> util = new ExcelUtil<LyhmsRoom>(LyhmsRoom.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(lyhmsRoomService.selectLyhmsRoomById(id));
    }

    /**
     * 新增
     */
    @PostMapping
    public AjaxResult add(@RequestBody LyhmsRoom lyhmsRoom) {
        return toAjax(lyhmsRoomService.insertLyhmsRoom(lyhmsRoom));
    }

    /**
     * 修改
     */
    @PutMapping
    public AjaxResult edit(@RequestBody LyhmsRoom lyhmsRoom) {
        return toAjax(lyhmsRoomService.updateLyhmsRoom(lyhmsRoom));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lyhmsRoomService.deleteLyhmsRoomByIds(ids));
    }

    @GetMapping("/ListNames/{type}")
    public AjaxResult ListName(@PathVariable("type") String type){
       List<LyhmsRoom> lyhmsRooms = lyhmsRoomService.ListName(type);
        return AjaxResult.success().put("list", lyhmsRooms);
    }

    @GetMapping(value = "byName/{room}")
    public AjaxResult getRoomInfo(@PathVariable("room") String name) {
        return AjaxResult.success(lyhmsRoomService.selectLyhmsRoomByName(name));
    }
}
